package cn.itcast.encapsulation;

public class Employee {
    private String name;
    private int age;
    private double salary;
    private String job;

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public double getSalary() {
        return salary;
    }

    public String getJob() {
        return job;
    }

    /**
     * 增加业务逻辑
     * @param name
     */
    public void setName(String name) {
        if (name.length() >= 2 && name.length() <= 6){
            this.name = name;
        }else {
            System.out.println("名字的长度不对，需要六个字符");
            this.name = "SB";
        }
    }

    public void setAge(int age) {
        if (age >= 1 && age <= 120){
            this.age = age;
        }else {
            System.out.println("年龄需要在1-120");
            //给一个默认年龄
            this.age = 18;
        }
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public void info(){
        System.out.println("信息:\nname="+name+"\nage="+age +
                "\nSalary="+salary+"\nJob="+job);
    }

    public Employee() {
        System.out.println("Git tag test");
    }

    public Employee(String name, int age, double salary, String job) {
        this.name = name;
        this.age = age;
        this.salary = salary;
        this.job = job;
    }

}
